env: fix crash using default -f -a
authorGerlando Falauto <[email protected]>
Fri, 5 Oct 2012 00:46:10 +0000 (00:46 +0000)
committerTom Rini <[email protected]>
Fri, 5 Oct 2012 18:07:42 +0000 (11:07 -0700)
env default -a -f calls env_check_apply on all existing environment
variables with a NULL value for "newval" as a way of cleaning up.
This causes string manipulation functions to crash on most architectures.
So replace a NULL argument with an empty string.

Reported-By: Stefano Babic <[email protected]>
Signed-off-by: Gerlando Falauto <[email protected]>
Tested-by: Stefano Babic <[email protected]>
common/cmd_nvedit.c

index 8ecc4982309874e4cbfe8c1c0b6e0dd0efb17010..bb1d4ec3e54df90a6df9d8ce7de7add30b1b3b90 100644 (file)
@@ -215,6 +215,9 @@ int env_check_apply(const char *name, const char *oldval,
 {
        int   console = -1;
 
+       /* Default value for NULL to protect string-manipulating functions */
+       newval = newval ? : "";
+
        /* Check for console redirection */
        if (strcmp(name, "stdin") == 0)
                console = stdin;